﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace BDH.DAL 
{
    using BDH.DAL.Entities;
    public class QuanDAL : BaseDAL, BDH.UTL.IBaseDAL
    {        
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            string sql = @" SELECT id,ma,ten FROM Quan ";
            return ExecuteQuery(sql);
        }

        public DataTable SelectAll()
        {
            string sql = @" SELECT q.id as quan_id, p.id as phuong_id, d.id as duong_id, ten, tenphuong, tenduong
                            FROM Quan q JOIN Phuong p ON q.id = p.quan_id
                                        JOIN Duong d ON p.id = d.phuong_id
                          ";
            return ExecuteQuery(sql);
        }

        public DataTable Select(string id)
        {
            throw new NotImplementedException();
        }

        public DataTable Select(int id)
        {
            throw new NotImplementedException();
        }

        public DataTable Select(string id1, string id2)
        {
            throw new NotImplementedException();
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(long id)
        {
            string sql = @" DELETE FROM Quan WHERE id = {0} ";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (Quan)obj;
            string sql = @" INSERT INTO Quan(ma,ten) VALUES('{0}', N'{1}') ";
            sql = string.Format(sql, o.ma, o.ten);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (Quan)obj;
            string sql = @" UPDATE Quan SET ten = N'{0}' WHERE id = {1} ";
            sql = string.Format(sql, o.ten, o.id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        
    }
}
